package JDBC;


import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCDemo101 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入用户名");
        String username=scanner.nextLine();
        System.out.println("请输入用户密码");
        String password=scanner.nextLine();
        System.out.println("请输入用户小名");
        String nickname=scanner.nextLine();
        System.out.println("请输入用户年龄");
        String age=scanner.nextLine();


        try (Connection conn=DBUtil.getConnection();){
            String sql="INSERT INTO userinfo(username,password,nickname,age) " +
                    "VALUES(username='"+username+"', " +
                    "password='"+password+"', " +
                    "nickname='"+nickname+"', " +
                    "age='"+age+"' )";

            Statement stmt=conn.createStatement();

            int num= stmt.executeUpdate(sql);
            System.out.println(num>0?"注册成功":"注册失败");
            System.out.println("插入了"+num+"组信息");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }
}
